#include "PrecompiledHeader.h"
#include "ICalc.h"

/*--------------------------------------------------------------------------*/

ICalc::ICalc()
{

}

/*--------------------------------------------------------------------------*/

ICalc::~ICalc()
{

}

/*--------------------------------------------------------------------------*/

void ICalc::DoCalc(uint arg)
{
	AssertLogC(arg >= ICALC_MAX_TASKS_NUM, "Wrong argument!");
	CalcDesc& cd = this->m_calcargs[arg];

	if (cd.m_nextIteration == 0 || g_Sdl->GetTicks() > cd.m_nextIteration)
	{
		this->OnPreCalc(arg);
		this->OnCalc(arg);
		this->OnPostCalc(arg);
	}

	if (cd.m_enabled)
	{
		g_Calc->AddToNextFrame(this, cd.m_flags, arg);
	}
}

/*--------------------------------------------------------------------------*/

void ICalc::StartTask(uint arg, const CalcDesc& calcDesc)
{
	AssertLogC(arg >= ICALC_MAX_TASKS_NUM, "Wrong argument!");
	this->m_calcargs[arg] = calcDesc;

	if (calcDesc.m_enabled)
	{
		g_Calc->AddToNextFrame(this, calcDesc.m_flags, arg);
	}
}

/*--------------------------------------------------------------------------*/

void ICalc::StopTask(uint arg)
{
	AssertLogC(arg >= ICALC_MAX_TASKS_NUM, "Wrong argument!");

	this->m_calcargs[arg].m_enabled = false;
}

/*--------------------------------------------------------------------------*/

void ICalc::AddTaskToCurrentQueue(uint arg)
{
	AssertLogC(arg >= ICALC_MAX_TASKS_NUM, "Wrong argument!");

	CalcDesc& cd = this->m_calcargs[arg];
	g_Calc->AddToCurrent(this, cd.m_flags, arg);
}

/*--------------------------------------------------------------------------*/

void ICalc::SetCalcFlag(uint arg, uint type)
{
	AssertLogC(arg >= ICALC_MAX_TASKS_NUM, "Wrong argument!");

	this->m_calcargs[arg].m_flags = type;
}

/*--------------------------------------------------------------------------*/

uint ICalc::GetCalcFlag(uint arg) const
{
	AssertLogC(arg >= ICALC_MAX_TASKS_NUM, "Wrong argument!");

	return this->m_calcargs[arg].m_flags;
}

/*--------------------------------------------------------------------------*/

void ICalc::OnPreCalc(uint arg)
{

}

/*--------------------------------------------------------------------------*/

void ICalc::OnPostCalc(uint arg)
{

}

/*--------------------------------------------------------------------------*/